package com.chainyoung.component_tmperson.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chainyoung.common.appcommon.entity.HdWalletCache;
import com.chainyoung.common.utils.StringUtil;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.ui.activity.hdwallet.HdWalletSettingActivity;

import java.math.BigDecimal;
import java.util.List;

public class LocalWalletListAdapter extends BaseQuickAdapter<HdWalletCache, BaseViewHolder> {


    private boolean isShowAsset = true;

   /* public LocalWalletListAdapter(@Nullable List<HdWallet> data) {
        super(R.layout.tmperson_layout_wallet_item, data);
        imageLoader = Utils.getAppComponent().imageLoader();
    }*/

    public LocalWalletListAdapter(@Nullable List<HdWalletCache> data) {
        super(R.layout.tmperson_layout_wallet_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final HdWalletCache item) {
        helper.setText(R.id.coin_name, item.getWalletName());
        helper.setText(R.id.coin_num, !isShowAsset ? "****" : TextUtils.isEmpty(item.getBalance()) ? "0" : item.getBalance().equals("0") ? "0" : StringUtil.subZeroAndDot(new BigDecimal(item.getBalance()).setScale(8, BigDecimal.ROUND_DOWN) + ""));
        helper.setText(R.id.coin_cny_amount, !isShowAsset ? "****" : "≈CNY " + item.getBanlanceCny());

       /* if (item.getCoinType().equals(ETH)) {
            //((ImageView) helper.getView(R.id.coin_logo)).setImageResource(item.getLogo());
            ((ImageView) helper.getView(R.id.coin_logo)).setImageResource(R.mipmap.icon_eth);
        }*/
        int logo = R.mipmap.icon_eth;
        ((ImageView) helper.getView(R.id.coin_logo)).setImageResource(logo);


        helper.getView(R.id.rl_purse).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, HdWalletSettingActivity.class);
                intent.putExtra("hdwallet", item);
                mContext.startActivity(intent);
            }
        });


//        helper.getView(R.id.btn_charge).setOnClickListener(onClickListener);
//        helper.getView(R.id.btn_cash).setOnClickListener(onClickListener);
//        helper.getView(R.id.btn_trade).setOnClickListener(onClickListener);
//
//        helper.getView(R.id.btn_charge).setTag(item);
//        helper.getView(R.id.btn_cash).setTag(item);
//        helper.getView(R.id.btn_trade).setTag(item);
    }

    public void setShowAsset(boolean showAsset) {
        isShowAsset = showAsset;
    }

//    private View.OnClickListener onClickListener = new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//            Purse item = (Purse) v.getTag();
//            if (v.getId() == R.id.btn_charge) {
//                Intent intent = new Intent(mContext, ChargeActivity.class);
//                intent.putExtra(COIN_NAME, item.getName());
//                intent.putExtra(COIN_CN_NAME, item.getTitle());
//                mContext.startActivity(intent);
//            } else if (v.getId() == R.id.btn_cash) {
//                Intent intent = new Intent(mContext, MakeCashActivity.class);
//                intent.putExtra(COIN_NAME, item.getName());
//                intent.putExtra(COIN_CN_NAME, item.getTitle());
//                intent.putExtra(ZC_FEE, item.getZcfee());
//                mContext.startActivity(intent);
//            } else if (v.getId() == R.id.btn_trade) {
//                RouterUtils.getInstance()
//                        .build(RouterConstants.PATH_MAIN_MARKET_ACTIVITY)
//                        .withInt("page", 1)
//                        .navigation(mContext);
//            }
//        }
//    };


}
